//
//  WDModifyPwdViewModel.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/17.
//

#import "WDModifyPwdViewModel.h"

@implementation WDModifyPwdViewModel

- (void)initialize {
    [super initialize];
    
    self.title = @"修改密码";
    
    _reqModel = [WDModifyPasswordReqModel new];
    _reqModel.userId = @([EDSAppDelegateTool sharedInstance].userInfoModel.userId);
}

/// 修改密码
/// - Parameter completion: completion description
- (void)requestWithMoifyPwd:(RequestCompletionBlock)completion {
    @weakify(self);
    WDModifyPasswordRequest *request = [[WDModifyPasswordRequest alloc] initWithModel:self.reqModel];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
//        EDSRespondDataEntity *respond = request.responseModelObject;
        
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 退出登录
/// - Parameter completion: completion description
- (void)requestWithLogout:(RequestCompletionBlock)completion {
    @weakify(self);
    WDAppLogoutRequest *request = [[WDAppLogoutRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            ZHCustomUserInfoModel *userInfo = [[EDSAppDelegateTool sharedInstance] getUserInfo];
            userInfo.loginState = 0;
            userInfo.appToken = @"";
            [[EDSAppDelegateTool sharedInstance] saveUserInfo:userInfo];
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
